﻿using SD.Toolkits.Mapper;
using SlamDunk.MES.Domain.Entities.ResourceContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.FoundationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ResourceContext;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Maps
{
    /// <summary>
    /// 资源定义相关映射
    /// </summary>
    public static class ResourceMap
    {
        #region # 人员类映射 —— static PersonClassInfo ToDTO(this PersonClass...
        /// <summary>
        /// 人员类映射
        /// </summary>
        public static PersonClassInfo ToDTO(this PersonClass personClass, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            PersonClassInfo classInfo = personClass.Map<PersonClass, PersonClassInfo>();
            classInfo.ParentNodeId = personClass.ParentNode?.Id;
            classInfo.FacilityInfo = personClass.FacilityId.HasValue
                ? facilityInfos?[personClass.FacilityId.Value]
                : null;

            return classInfo;
        }
        #endregion

        #region # 人员映射 —— static PersonInfo ToDTO(this Person person...
        /// <summary>
        /// 人员映射
        /// </summary>
        public static PersonInfo ToDTO(this Person person, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            PersonInfo personInfo = person.Map<Person, PersonInfo>();
            personInfo.FacilityInfo = person.FacilityId.HasValue
                ? facilityInfos?[person.FacilityId.Value]
                : null;

            return personInfo;
        }
        #endregion

        #region # 班组映射 —— static TeamInfo ToDTO(this Team team...
        /// <summary>
        /// 班组映射
        /// </summary>
        public static TeamInfo ToDTO(this Team team, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            TeamInfo teamInfo = team.Map<Team, TeamInfo>();
            teamInfo.FacilityInfo = team.FacilityId.HasValue
                ? facilityInfos?[team.FacilityId.Value]
                : null;

            return teamInfo;
        }
        #endregion

        #region # 班组成员映射 —— static TeamMemberInfo ToDTO(this TeamMember teamMember...
        /// <summary>
        /// 班组成员映射
        /// </summary>
        public static TeamMemberInfo ToDTO(this TeamMember teamMember, IDictionary<Guid, PersonInfo> personInfos)
        {
            TeamMemberInfo teamMemberInfo = teamMember.Map<TeamMember, TeamMemberInfo>();
            teamMemberInfo.PersonInfo = personInfos?[teamMember.PersonId];

            return teamMemberInfo;
        }
        #endregion

        #region # 设备类映射 —— static EquipmentClassInfo ToDTO(this EquipmentClass...
        /// <summary>
        /// 设备类映射
        /// </summary>
        public static EquipmentClassInfo ToDTO(this EquipmentClass equimentClass, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            EquipmentClassInfo classInfo = equimentClass.Map<EquipmentClass, EquipmentClassInfo>();
            classInfo.ParentNodeId = equimentClass.ParentNode?.Id;
            classInfo.FacilityInfo = equimentClass.FacilityId.HasValue
                ? facilityInfos?[equimentClass.FacilityId.Value]
                : null;

            return classInfo;
        }
        #endregion

        #region # 设备映射 —— static EquipmentInfo ToDTO(this Equipment equipment...
        /// <summary>
        /// 设备映射
        /// </summary>
        public static EquipmentInfo ToDTO(this Equipment equipment, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            EquipmentInfo equipmentInfo = equipment.Map<Equipment, EquipmentInfo>();
            equipmentInfo.FacilityInfo = equipment.FacilityId.HasValue
                ? facilityInfos?[equipment.FacilityId.Value]
                : null;

            return equipmentInfo;
        }
        #endregion

        #region # 物料类映射 —— static MaterialClassInfo ToDTO(this MaterialClass...
        /// <summary>
        /// 物料类映射
        /// </summary>
        public static MaterialClassInfo ToDTO(this MaterialClass materialClass, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            MaterialClassInfo classInfo = materialClass.Map<MaterialClass, MaterialClassInfo>();
            classInfo.ParentNodeId = materialClass.ParentNode?.Id;
            classInfo.FacilityInfo = materialClass.FacilityId.HasValue
                ? facilityInfos?[materialClass.FacilityId.Value]
                : null;

            return classInfo;
        }
        #endregion

        #region # 物料定义映射 —— static MaterialInfo ToDTO(this Material material...
        /// <summary>
        /// 物料定义映射
        /// </summary>
        public static MaterialInfo ToDTO(this Material material, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            MaterialInfo materialInfo = material.Map<Material, MaterialInfo>();
            materialInfo.MaterialPackInfo = material.MaterialPack?.ToDTO();
            materialInfo.MaterialBarcodeSettingInfo = material.MaterialBarcodeSetting?.ToDTO();
            materialInfo.FacilityInfo = material.FacilityId.HasValue
                ? facilityInfos?[material.FacilityId.Value]
                : null;

            return materialInfo;
        }
        #endregion

        #region # 物料包装映射 —— static MaterialInfo ToDTO(this Material material...
        /// <summary>
        /// 物料包装映射
        /// </summary>
        public static MaterialPackInfo ToDTO(this MaterialPack materialPack)
        {
            MaterialPackInfo materialPackInfo = materialPack.Map<MaterialPack, MaterialPackInfo>();

            return materialPackInfo;
        }
        #endregion

        #region # 物料条码设置映射 —— static MaterialBarcodeSettingInfo ToDTO(this MaterialBarcodeSetting...
        /// <summary>
        /// 物料条码设置映射
        /// </summary>
        public static MaterialBarcodeSettingInfo ToDTO(this MaterialBarcodeSetting materialBarcodeSetting)
        {
            MaterialBarcodeSettingInfo settingInfo = materialBarcodeSetting.Map<MaterialBarcodeSetting, MaterialBarcodeSettingInfo>();

            return settingInfo;
        }
        #endregion

        #region # 企业映射 —— static EnterpriseInfo ToDTO(this Enterprise enterprise...
        /// <summary>
        /// 企业映射
        /// </summary>
        public static EnterpriseInfo ToDTO(this Enterprise enterprise, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            EnterpriseInfo enterpriseInfo = enterprise.Map<Enterprise, EnterpriseInfo>();
            enterpriseInfo.FacilityInfo = enterprise.FacilityId.HasValue
                ? facilityInfos?[enterprise.FacilityId.Value]
                : null;

            return enterpriseInfo;
        }
        #endregion
    }
}
